<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2012-01-01 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

require ROOT_PATH.'module/admin/master.mod.php';

class moduleObj extends masterObj
{
	var $ioHandler = '';
	
	function __construct($request)
	{
		parent::__construct($request);

		require_once ROOT_PATH.'lib/io.han.php';
		$this->ioHandler = new IoHandler();
		
		$this->excute();
	}
	
	function excute()
	{
		ob_start();
		
		switch($this->act)
		{
			case 'modify_normal':
				$this->modifyNormal();
				break;
			case 'shortcut';
				$this->shortcut();
				break;
			case 'modify_shortcut':
				$this->doModifyShortcut();
				break;
			default:
				$this->main();
				break;
		}
		
		$body = ob_get_clean();
		
		$this->showBody($body);
	}
	
	private function main()
	{
		
	}
	
	private function modifyNormal()
	{
		
	}
	
	private function shortcut()
	{
		unset($menu_list);
		
		$action = 'modify_shortcut';
		
		include(ROOT_PATH.'config/menu_list_admin.php');

		include template('admin/setting_shortcut');
	}
	
	private function doModifyShortcut()
	{
		unset($menu_list);
		
		$cfg_file = ROOT_PATH.'config/menu_list_admin.php';
		include($cfg_file);

		$post_menulist = isset($this->request['menu_list']) ? $this->request['menu_list'] : array();
		
		if(!check_array($post_menulist))
		{
			$this->Messager("请求错误", 'admin.php?m=setting&a=shortcut');
		}
		
		foreach($menu_list as $m_key=>$m_val)
		{
			if($m_val['sub_menu_list'] && is_array($m_val['sub_menu_list']) && count($m_val['sub_menu_list']))
			{
				foreach ($m_val['sub_menu_list'] as $s_m_key=>$s_m_val)
				{
					if(isset($post_menulist[$m_key]) && isset($post_menulist[$m_key][$s_m_key]))
					{
						$menu_list[$m_key]['sub_menu_list'][$s_m_key]['shortcut'] = (boolean)$post_menulist[$m_key][$s_m_key]['shortcut'];
					}
					else
					{
						$menu_list[$m_key]['sub_menu_list'][$s_m_key]['shortcut'] = false;
					}
				}
			}
		}

		$this->ioHandler->WriteFile($cfg_file, '<?php $menu_list = '.var_export($menu_list,true).'; ?>');
		
		$this->Messager("修改成功", 'admin.php');
	}
}